/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package OtrosTPs.TP3;

import OtrosTPs.TP1.LevenshteinDistance;
import java.util.ArrayList;

/**
 *
 * @author ivanpianetti
 */
public class GNAT {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        ArrayList<String> cadenas = new ArrayList<String>();
        cadenas.add("Zulma");
        cadenas.add("Fernando");
        cadenas.add("Charlize");
        cadenas.add("Ana");
        cadenas.add("Alan");
        cadenas.add("Amy");
        cadenas.add("Adrian");
        cadenas.add("Anahi");
        cadenas.add("Anama");
        cadenas.add("Belen");
        cadenas.add("Cameron");
        cadenas.add("Claudia");
        cadenas.add("Clara");
        cadenas.add("Cristian");
        cadenas.add("Esteban");
        cadenas.add("Estanislao");
        cadenas.add("Jorge");
        cadenas.add("Francisco");
        cadenas.add("Paula");
        cadenas.add("Pedro");
        System.out.println("Cantidad de cadenas: " + cadenas.size());
        System.out.println("************Nivel 1 ************");
        calcGNAT(cadenas, "Belen", "Charlize", "Fernando", "Zulma");

        System.out.println("************Nivel 2: Belen************");
        cadenas = new ArrayList<String>();
        cadenas.add("Alan");
        cadenas.add("Adrian");
        cadenas.add("Anahi");
        cadenas.add("Cameron");
        cadenas.add("Esteban");
        cadenas.add("Jorge");
        cadenas.add("Pedro");

        calcGNAT(cadenas, "Alan", "Pedro", "Jorge", "Anahi");

        System.out.println("************Nivel 2: Zulma************");
        cadenas = new ArrayList<String>();
        cadenas.add("Ana");
        cadenas.add("Amy");
        cadenas.add("Anama");
        cadenas.add("Clara");
        cadenas.add("Paula");
        calcGNAT(cadenas, "Amy", "Clara", "Paula", "Anama");




//        System.out.println("\n##########Centro:##########");
//        mostrar(calcConsultaCentro(cadenas, "Alan", 2));
//        mostrar(calcConsultaRango(cadenas, "Pablo", 4));
//        mostrar(calcConsultaRango(cadenas, "Roberto", 3));
//        System.out.println("\n##########NN:##########");
//        mostrar(calcConsultaNN(cadenas, "Susana"));
//        System.out.println("\n##########NNk:##########");
//        mostrar(calcConsultaNNk(cadenas, "Florencia", 4));
    }

    private static void calcGNAT(ArrayList<String> cadenas, String e1, String e2, String e3, String e4) {
        int i = 0;
        ArrayList<String> listaE1 = new ArrayList<String>();
        ArrayList<String> listaE2 = new ArrayList<String>();
        ArrayList<String> listaE3 = new ArrayList<String>();
        ArrayList<String> listaE4 = new ArrayList<String>();
        for (int t = i; t < cadenas.size(); t++) {
            String c = cadenas.get(t);

            int distE1 = LevenshteinDistance.computeLevenshteinDistance(e1, c);
            int distE2 = LevenshteinDistance.computeLevenshteinDistance(e2, c);
            int distE3 = LevenshteinDistance.computeLevenshteinDistance(e3, c);
            int distE4 = LevenshteinDistance.computeLevenshteinDistance(e4, c);

            if (distE1 <= distE2 && distE1 <= distE3 && distE1 <= distE4) {
                listaE1.add(c + "=" + distE1);
            } else {
                if (distE2 <= distE1 && distE2 <= distE3 && distE2 <= distE4) {
                    listaE2.add(c + "=" + distE2);
                } else {
                    if (distE3 <= distE1 && distE3 <= distE2 && distE3 <= distE4) {
                        listaE3.add(c + "=" + distE3);
                    } else {
                        if (distE4 <= distE1 && distE4 <= distE3 && distE4 <= distE2) {
                            listaE4.add(c + "=" + distE4);
                        }
                    }
                }
            }
        }
        System.out.println("====> " + e1);
        for (String resp : listaE1) {
            System.out.println(resp);
        }
        System.out.println("====> " + e2);
        for (String resp : listaE2) {
            System.out.println(resp);
        }
        System.out.println("====> " + e3);
        for (String resp : listaE3) {
            System.out.println(resp);
        }
        System.out.println("====> " + e4);
        for (String resp : listaE4) {
            System.out.println(resp);
        }

        System.out.println("\nTABLA DE DISTANCIAS MAXIMAS");
        calcMaximo(e1, listaE2);
        calcMaximo(e1, listaE3);
        calcMaximo(e1, listaE4);

        calcMaximo(e2, listaE1);
        calcMaximo(e2, listaE3);
        calcMaximo(e2, listaE4);

        calcMaximo(e3, listaE1);
        calcMaximo(e3, listaE2);
        calcMaximo(e3, listaE4);

        calcMaximo(e4, listaE1);
        calcMaximo(e4, listaE2);
        calcMaximo(e4, listaE3);

        System.out.println("\nTABLA DE DISTANCIAS MINIMAS");
        calcMinimo(e1, listaE2);
        calcMinimo(e1, listaE3);
        calcMinimo(e1, listaE4);

        calcMinimo(e2, listaE1);
        calcMinimo(e2, listaE3);
        calcMinimo(e2, listaE4);

        calcMinimo(e3, listaE1);
        calcMinimo(e3, listaE2);
        calcMinimo(e3, listaE4);

        calcMinimo(e4, listaE1);
        calcMinimo(e4, listaE2);
        calcMinimo(e4, listaE3);

    }

    private static void calcMinimo(String elemento, ArrayList<String> lista) {
        int min = 90000000;
        String resp = "";
        for (String c : lista) {
            c = c.split("=")[0];
            int dist = LevenshteinDistance.computeLevenshteinDistance(elemento, c);
            if (dist < min) {
                min = dist;
                resp = "Min dist(" + elemento + ";" + c + ")=" + dist;
            }
        }
        System.out.println(resp);
    }

    private static void calcMaximo(String elemento, ArrayList<String> lista) {
        int max = -1;
        String resp = "";
        for (String c : lista) {
            c = c.split("=")[0];
            int dist = LevenshteinDistance.computeLevenshteinDistance(elemento, c);
            if (dist > max) {
                max = dist;
                resp = "Max dist(" + elemento + ";" + c + ")=" + dist;
            }
        }
        System.out.println(resp);
    }
}
